package org.apache.commons.dbcp;

import java.sql.SQLException;

import javax.sql.DataSource;


public class MySQLDataSource extends BasicDataSource {
	
	@Override
	protected synchronized DataSource createDataSource() throws SQLException {
		ClassLoader cl = this.getClass().getClassLoader(); // Bundle的ClassLoader
		ClassLoader threadCl = Thread.currentThread().getContextClassLoader(); // 线程的CLassLoader
		try {
			Thread.currentThread().setContextClassLoader(cl); // 把线程的ClassLoader设置为Bundle的ClassLoader
			return super.createDataSource();
		} finally {
			Thread.currentThread().setContextClassLoader(threadCl); // 还原ClassLoader
		}
	}
}
